import java.util.Scanner;
public class Text {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int a= scan.nextInt();
        int b=scan.nextInt();
        int c=a%b;
        while(c!=0){
            a=b;
            b=c;
            c=a%b;
        }
        System.out.println(b);
    }
    public static void main6(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int count=0;
        for (int i = 0; i < 32; i++) {
            if(n==0){
                break;
            }
            if((n&1)==1){
                count++;
            }
            n=n>>>1;
        }
        System.out.println(count);
    }
    public static void main5(String[] args) {
        Scanner scan=new Scanner(System.in);
        int num=scan.nextInt();
        int i=0;
        for ( i = 2; i <= Math.sqrt(num); i++) {
            if(num%i==0){
                System.out.println(num+"不是素数");
                break;
            }
        }
        if(i>Math.sqrt(num)){
            System.out.println(num+"是素数");
        }
    }
    public static void main4(String[] args) {
        for (int i = 1000; i <= 2000; i++) {
            if((i%100!=0)&&(i%4==0)||i%400==0){
                System.out.print(i+" ");
            }
        }
    }
    public static void main3(String[] args) {
        int i=1;
        int count=0;
        for (i = 1; i <= 100; i++) {
            if(i%10==9){
                count++;
            }
            if(i/10==9){
                count++;
            }
        }
        System.out.println(count);
    }
    public static void main2(String[] args) {
        int i=1;
        int j=0;
        for(;i <= 100;i++){
            for (j = 2; j <= Math.sqrt(i); j++) {
                if(i%j == 0){
                    break;
                }
            }
            if(j>Math.sqrt(i)){
                System.out.print(i+" ");
            }
        }
    }
    public static String myToString(int[] array){
        String ret="[";
        for (int i = 0; i < array.length-1; i++) {
            ret=ret+array[i]+",";
        }
            ret=ret+array[array.length-1]+"]";
        return ret;
    }
    public static void main1(String[] args) {
        int[] array={1,2,3,4,5};
        System.out.println(myToString(array));
    }
}
